<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet" type="text/css" />
<link href="__UI__/css/bs3/bui.css" rel="stylesheet" type="text/css" />
<link href="__UI__/css/style.css" rel="stylesheet" type="text/css" />
<link href="__UI__/uploadify/uploadify.css" rel="stylesheet" type="text/css">
<style type="text/css">

button {
	margin-right:20px;
}

.imageViewTheme .bui-uploader-button-wrap {
	margin-bottom:10px;;
	margin-left:10px;
}

.image{
	float:left;
	width:300px;
	padding:10px auto;
	display:block;
}

.image .photo{
	width:300px;
	height:auto;
	overflow:hidden;
	float:left;
}

.image img{
	display:inline-block;
	width:200px;
	height:auto;
	overflow:hidden;
	float:left;
}

.image .del{
	display:inline-block;
	float:right;
	width:100px;
}

.buttons {
    display: inline-block;
    margin-bottom: 0;
    font-weight: normal;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    background-image: none;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 20px;
    padding: 4px 12px;
    font-size: 14px;
    border-radius: 4px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    color: #ffffff;
    background-color: #000000;
    border-color: #cccccc;
}

.btns span{
	display:block;
	margin:5px auto;
}

.selects{
	float:left;
	min-height:100px;
	height:auto;
	overflow:hidden;
}

.selects .lists{
	float:left;
	width:220px;
	height:200px;
}

.selects .direction{
	float:left;
	width:80px;
	height:200px;
}

.selects option {
	height:20px;
	line-height:20px;
	padding:2px;
}

</style>
</head>
<body>
<div class="demo-content" style="margin-top:1%;">
    <div class="row" style="margin-left:10px;">
        <form id="J_Form" action="{:U('Home/Record/edit')}" class="form-horizontal registerform" method="post" enctype="multipart/form-data">
        	<div style="text-align:center"><h2>{$scripts.scriptsname} - 场景演练</h2><hr></div>
        	<div id="tab" style="margin-left:1%; padding-bottom:20px; padding-top:20px;"></div>
            <div id="panel" class="" style="padding:10px;">
                <input name="sid" type="hidden" value="{:I('get.sid')}">
                <input name="uid" type="hidden" value="{:session('gid')}">
                <input name="mid" type="hidden" value="{:session(C('AUTH_KEYS'))}">
                <input name="pid" type="hidden" value="{:I('get.pid')}">
                <input name="title" type="hidden" value="{$scripts.scriptsname}">
                <input name="build" type="hidden" value="1">
                <div class="control-group">
					<label class="control-label"><s>*</s>演练主控官</label>
					<div class="controls">
						<input type="text" name="management" id="management" datatype="*" nullmsg="请输入场景名称！" data-tip="{text:'请输入场景名称'}" style="width:600px;" />
					</div>
				</div>
                <div class="control-group">
					<label class="control-label"><s>*</s>演练记录人</label>
					<div class="controls">
						<input type="text" name="recordman" id="recordman" datatype="*" nullmsg="请输入场景名称！" data-tip="{text:'请输入场景名称'}" style="width:600px;" />
					</div>
				</div>
                <div class="control-group">
					<label class="control-label"><s>*</s>演练地点</label>
					<div class="controls">
						<input type="text" name="address" id="address" datatype="*" nullmsg="请输入场景名称！" data-tip="{text:'请输入场景名称'}" style="width:600px;" />
					</div>
				</div>
                <div class="control-group">
					<label class="control-label"><s>*</s>演练时间</label>
					<div class="controls" style="margin-bottom:80px;">
						
					</div>
				</div>
                <div class="row actions-bar">
                	<span id="msgdemo2"></span>
                    <div class="form-actions span13 offset3">
                        <button type="submit" class="button button-primary">保存</button>
                        <button type="reset" class="button">重置</button>
                        <button type="button" class="button button-info" name="backid" id="backid">返回</button>
                    </div>
            	</div>           
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript">
	function selected(thiz)
	{
		var name = thiz.name;
		if(name=="department[]")
			$("select[name='left']").val("");
		else
			$("select[name='department[]']").val("");
	}
	function Shift(thiz)
	{
		var right = $("select[name='department[]']");
		var left = $("select[name='left']");
		if(thiz=="left" && right.val() != ""){
			lrShift(right,left);
		}else if(thiz=="right" && left.val() != ""){
			lrShift(left,right);
		}

		//获取选中的值
	}
	//从dest移动到target
	function lrShift(dest,target)
	{
		var childrens = dest.children();
		var args = "";
		//alert(dest.val());
		var dests = dest.val()
		for(var x = 0; x < dests.length; x++)
		{
			var vaTemp = dests[x];
			target.append("<option value='"+vaTemp+"'>"+vaTemp+"</option>");//追加
			target.find("option[value='"+vaTemp+"']").attr("selected",true);//给追加获取焦点
			for(var y = 0; y <childrens.length;y++ )//删除选中的元素
			{
				if(childrens.get(y).value==vaTemp)
					$(childrens.get(y)).remove();
			}
		}
		dest.val("");
	}
	function ShiftValue(address)
	{
		var right = $("select[name='department[]']");
		var left = $("select[name='left']");
		if(right.val()!=null)
			shift(right,address);
		else if(left.val()!=null)
			shift(left,address);
	}
	function shift(obj,address){
			//获取选中的值
			var objData = obj.val();
			var childrens = obj.children();
			var strs = "";
			for(var x = 0; x < objData.length; x++)
			{
				strs+="@"+objData[x];
			}

			//获取要添加位置对象
			var temp = null;
			if(address=="top"){
				var number = findSelect(childrens,objData[0]);
				if((--number) < 0)
					return;
				temp = childrens.get(number);
			}
			else{
				var number = findSelect(childrens,objData[objData.length-1]);
				if((++number) > childrens.length-1)
					return;
				temp = childrens.get(number);
			}

			//删除选中的值
			var n = 0;
			var buffer = new Array(childrens.length-objData.length);
			for(var x = 0; x < childrens.length;x++)
			{
				var value = childrens.get(x).value;
				if(strs.indexOf(value)==-1)
					buffer[n++] = value;
			}

			//添加新排序的值
			obj.empty();
			if(address=="top")
			{
				for(var y = 0; y < buffer.length;y++)
				{
					if(buffer[y]==temp.value)
					{
						for(var x = 0; x < objData.length ; x++)
						{
							obj.append("<option>"+objData[x]+"</option>");
						}
					}
					obj.append("<option>"+buffer[y]+"</option>");
				}
			}else{
				for(var y = 0; y < buffer.length;y++)
				{
					obj.append("<option>"+buffer[y]+"</option>");
					if(buffer[y]==temp.value)
					{
						for(var x = 0; x < objData.length; x++)
						{
							obj.append("<option>"+objData[x]+"</option>");
						}
					}
				}
			}
			//选中值
			obj.val(objData);
	}
	function findSelect(selects,objValue)
	{
		var number = -1;
		for(var x = 0; x < selects.length; x++)
		{
			if(objValue==selects.get(x).value)
				number = x;
		}
		return number;
	}

	$(function () {
		$('#section').click(function(){
			var d = $('#titles').val();
			if(d == ''){
				BUI.Message.Alert('请输入部门名称！');
			}else{
				$.ajax({
					type:'post',
					url:'{:U("Home/Department/add")}',
					dataType:'json',
					data:{title:d},
					success:function(data){
						if(data.status == 'y'){
							$("#titles").attr("value",'');
							$("#title").append( "<option value=" + d +">"+d+"</option>" );
							BUI.Message.Alert('增加成功！');
						}else{
							BUI.Message.Alert('删除失败！');
						}
					}
				});
			}
		});
    });
	$(document).ready(function() {  
		var MaxInputs       = 100000; //maximum input boxes allowed  
		var InputsWrapper   = $("#InputsWrapper"); //Input boxes wrapper ID  
		var AddButton       = $("#AddMoreFileBox"); //Add button ID  
		var x = InputsWrapper.length; //initlal text box count  
		var FieldCount=1; //to keep track of text box added  
  		$(AddButton).click(function (e)  //on add input button click  
		{  
        	if(x <= MaxInputs) //max input box allowed  
        	{  
            	FieldCount++; //text box added increment  
            //add input box  
            	$(InputsWrapper).append('<div style="margin:5px auto"><input type="text" name="hint[]" id="field_'+ FieldCount +'" style="width:510px;"/>&nbsp;&nbsp;&nbsp;<span class="buttons button-inverse removeclass">删除提示</span>');  
            	x++; //text box increment  
        	}  
			return false;  
		});  
		$("body").on("click",".removeclass", function(e){ //user click on remove text  
        	if( x > 1 ) {  
				$(this).parent('div').remove(); //remove text box  
				x--; //decrement textbox  
        	}  
			return false;  
		})   
	});
	$(function () {
		$('#dels').click(function(){			
			$('#dels').attr("value",'');
		});
	});
	$(function () {       
		$('#backid').click(function(){
			top.topManager.openPage({
				id:'Scene_index',
				title:'场景管理',
				href:'{:U("Scene/index",array("id"=>I("get.id")))}',
				isClose:true,
				reload:true,
			});
		});
    });
	top.topManager.closePage('scene_index');
	top.topManager.closePage('scene_edit');
    BUI.use(['bui/tab','bui/mask'],function(Tab){
        var tab = new Tab.TabPanel({
            render:'#tab',
            elCls:'nav-tabs',
            panelContainer:'#panel',
            autoRender:true,
            children:[
                {title:'基本信息',value:'1',selected:true},
            ]
        });
    });
    BUI.use('bui/form', function (Form) {
        new Form.Form({
            srcNode:'#J_Form'
        }).render();
    });
	$(function(){
		$(".registerform").Validform({
			tiptype:function(msg,o,cssctl){
				var objtip=$("#msgdemo2");
				cssctl(objtip,o.type);
				objtip.text(msg);
			},
			ajaxPost:true,
			callback:function(data){
				if(data.status == 'y'){
					top.topManager.openPage({
						id:'record',
						title:'演练记录',
						href:'{:U("Record/index")}',
						isClose:false,
						reload:true,
					});
				}
			},
		});
	})
	function del(delName,delId){
		var d='#'+delName;
		var url = '{:U("Home/Scene/dels/")}';
		$.post(url,{'name':delId},function(data){
			$(d).html(data.info);
			$(d).hide(3000);
		},'json');
	}
	$(function() {
		$('#media').uploadify({
			'formData':{
				'timestamp':'{$time}',
				'token':'{$time | md5}',
				'url':'{:U("Home/Scene/uploadify/")}',
				'imageUrl':'__ROOT__'
			},
			'fileTypeDesc':'Image Files',
			'fileTypeExts':'*.gif; *.jpg; *.png; *.pdf; *.doc; *.docx',
			'fileSizeLimit':'3MB',
			'swf':'__UI__/uploadify/uploadify.swf',
			'uploader':'{:U("Home/Scene/uploadify")}',
			'buttonText':'文件上传',
			'onUploadSuccess':function(file, data, response){
				var n = parseInt(Math.random()*100);
				$('#image').append('<div id="'+n+'" class="photo"><img src="__ROOT__/Public/file/'+data+'"/><div class="del"><a href="javascript:vo(0)" onclick=del("'+n+'","./Public/file/'+data+'");return false;>删除</a></div></div><input name="media" type="hidden" value="./Public/file/'+data+'">');
			}
						
		});
	});
</script>
</body>
</html>